package be.cgi.heroesmanager.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import be.cgi.heroesmanager.R;
import be.cgi.heroesmanager.db.HeroesAdapter;
import be.cgi.heroesmanager.model.Hero;

public class AddActivity extends Activity {

	EditText etName, etCity, etAbility;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add);

		etName = (EditText) findViewById(R.id.etName);
		etCity = (EditText) findViewById(R.id.etCity);
		etAbility = (EditText) findViewById(R.id.etAbility);
	}
	
	public void btnSave_onClick(View v){
		String name = etName.getText().toString();
		String city = etCity.getText().toString();
		String ability = etAbility.getText().toString();
		
		Hero newHero = new Hero(name, city, ability);
		
		HeroesAdapter adap = new HeroesAdapter(getApplicationContext());
		adap.openWritable();
		adap.insert(newHero);
		adap.close();
		
		finish();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add, menu);
		return true;
	}

}
